<include file="public@header"/>
</head>
<body>
<div class="wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:url('showList')}">列表</a></li>
        <li><a href="{:url('showTreeTable')}">树</a></li>
        <li class="active"><a href="{:url('showCreateForm')}">新建</a></li>
    </ul>
	<form method="post" class="form-horizontal js-ajax-form margin-top-20" action="{:url('updateItem')}">
		<input type="hidden" name="id" value="{$item.id}">
		<div class="form-group">
			<label class="col-sm-2 control-label"><span class="form-required">*</span>上级分类:</label>
			<div class="col-md-6 col-sm-10">
				<!-- <input type="text" class="form-control" name="parent_id" value="{$id|default=''}"> -->
				<input class="form-control" type="text" style="width:400px;" required value="{$parent.title}"
					placeholder="请选择分类" onclick="doSelectCategory();" id="js-categories-name-input" readonly/>
				<input class="form-control" type="hidden" value="{$item.parent_id}" name="parent_id" id="js-categories-id-input"/>
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label"><span class="form-required">*</span>名称:</label>
			<div class="col-md-6 col-sm-10">
				<input type="text" class="form-control" name="name" value="{$item.name}">
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label">标题:</label>
			<div class="col-md-6 col-sm-10">
				<input type="text" class="form-control" name="title" value="{$item.title}">
			</div>
		</div>
		<div class="col-sm-offset-2 col-sm-10">
			<button type="submit" class="btn btn-primary js-ajax-submit">{:lang("SAVE")}</button>
			<a class="btn btn-default" href="__URL__">返回</a>
		</div>
	</form>
</div>
<script src="__STATIC__/js/admin.js"></script>
<script>
	function doSelectCategory() {
        var selectedCategoriesId = $('#js-categories-id-input').val();
        openIframeLayer("{:url('showTreeTableSelect')}?ids=" + selectedCategoriesId, '请选择分类', {
            area: ['700px', '400px'],
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                //do something

                var iframeWin          = window[layero.find('iframe')[0]['name']];
                var selectedCategories = iframeWin.confirm();
                if (selectedCategories.selectedCategoriesId.length == 0) {
                    layer.msg('请选择分类');
                    return;
                }
                $('#js-categories-id-input').val(selectedCategories.selectedCategoriesId.join(','));
                $('#js-categories-name-input').val(selectedCategories.selectedCategoriesName.join(' '));
                //console.log(layer.getFrameIndex(index));
                layer.close(index); //如果设定了yes回调，需进行手工关闭
            }
        });
    }
</script>
</body>
</html>
